package top.frsf.bullet;

import top.frsf.GamePanel;
import top.frsf.envir.Blast;
import top.frsf.tank.TankObj;
import top.frsf.tool.Direction;

import java.awt.*;
import java.util.ArrayList;

/**
 * @BelongsProject: TankWar1
 * @BelongsPackage: top.frsf.bullet
 * @Author: FRSF
 * @CreateTime: 2022-09-03  21:11
 * @Description: 人机tank子弹
 * @Version: 1.0
 */
public class EnemyBullet extends Bullet {
    public EnemyBullet(String img, int x, int y, GamePanel gamePanel, Direction direction) {
        super(img, x, y, gamePanel, direction);
    }

    @Override
    public void paintSelf(Graphics g) {
        super.paintSelf(g);
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }

    @Override
    public void hitBot() {
        ArrayList<TankObj> players = this.gamePanel.playerList;
        for (TankObj player : players) {
            if (this.getRec().intersects(player.getRec())) {
                player.alive = false;
                this.gamePanel.blastList.add(new Blast("", player.x + width / 2,
                        player.y + height / 2, this.gamePanel));
                this.gamePanel.playerList.remove(player);
                this.gamePanel.removeListBullets.add(this);
                break;
            }
        }
    }
}
